<template>
  <el-table :data="classInfoList" style="width: 100%">
    <el-table-column type="index" label="序号" width="55"/>
    <el-table-column prop="courseName" label="报名课程"/>
    <el-table-column prop="className" label="班级名称"/>
    <el-table-column prop="typeTxt" label="班级类型"/>
    <el-table-column prop="courseHour" label="总课时"/>
    <el-table-column prop="statusTxt" label="班级状态"/>
    <el-table-column prop="spendHour" label="已上课时"/>
    <el-table-column prop="courseProgress" label="课程进度">
      <template slot-scope="scope">
        <el-tooltip :content="(scope.row.spendHour + '/' + scope.row.courseHour)" class="item" effect="dark" placement="top">
          <el-progress :percentage="+((scope.row.spendHour) * 100 / scope.row.courseHour).toFixed(2)"/>
        </el-tooltip>
      </template>
    </el-table-column>
    <el-table-column label="操作" width="120">
      <template slot-scope="scope">
        <el-button type="text" @click="handleQuit(scope.$index, scope.row)">退课</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
import { quitCourse } from '@/api/student'

export default {
  props: {
    // eslint-disable-next-line vue/require-default-prop
    classInfoList: {
      type: Array,
      required: false
    }
  },
  data() {
    return {}
  },
  methods: {
    handleQuit: function(index, row) {
      this.$confirm('确定要退订改课程?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const para = {
          merchantStudentId: row.studentId,
          courseId: row.courseId
        }
        quitCourse(para).then(res => {
          this.$message({
            message: '退课成功！',
            type: 'success'
          })
          this.$emit("onQuitSuccess")
        }).catch(err => {
          this.$notify({
            title: '退课失败!',
            message: err.msg,
            type: 'error'
          })
        })
      })
    }
  }
}
</script>

<style>
</style>
